<template>
	<view class="" v-if="load&&load1">
		<view class="content1">
			<u-card :title="list.project_name" :sub-title="list.create_time">
				<view class="" slot="body">
					<u-row gutter="16">
						<u-col span="12">
							<view class="demo-layout bg-purple">充值总额：{{list.project_sum}}元</view>
						</u-col>
					</u-row>
					<u-row gutter="16">
						<u-col span="4">
							<view class="demo-layout bg-purple">已付:{{list.project_receipts}}元</view>
						</u-col>
						<u-col span="4" offset="4">
							<view class="demo-layout bg-purple">剩余:{{list.project_surplus}}元</view>
						</u-col>
					</u-row>
					<u-row gutter="16">
						<u-col span="4" offset="8">
							<u-button shape="square" size="mini" @click="stopDingdan">关闭订单</u-button>
						</u-col>
					</u-row>
				</view>
			</u-card>
			<view class="" slot="body">
				<u-row gutter="16">
					<u-col span='10' offset='1'>
						<u-form ref="uForm">
							<u-form-item left-icon='rmb' style="float: left;">
								<u-input placeholder="请输入金额" v-model="num" />
							</u-form-item>
						</u-form>
					</u-col>
				</u-row>
			</view>
			<view v-for="item in listXqing " :key="item.id">
				<u-card :title="title" :sub-title="arr[item.pay_status].text" :sub-title-color="arr[item.pay_status].class">
					<view class="" slot="body">
						<view class="u-body-item u-flex u-row-between u-p-b-0">
							<u-row gutter="16">
								<u-col span="12">
									<view class="demo-layout bg-purple">支付金额：+{{item.pay_amount}}元</view>
								</u-col>
							</u-row>
						</view>
						<view class="u-body-item u-flex u-row-between u-p-b-0">
							<u-row gutter="16">
								<u-col span="12">
									<view class="demo-layout bg-purple">支付订单：{{item.pay_order}}</view>
								</u-col>
							</u-row>
						</view>
						<u-row gutter="16" v-if="!arr[item.project_status].is_done">
							<u-col span="4">
									<u-button shape="square" size="mini" @click="stopLiushui(item.id)">关闭流水</u-button>
							</u-col>
							<u-col span="4" offset="4">
								<u-button shape="square" size="mini" @click="onceZhifu(item.id)">再次支付</u-button>
							</u-col>
						</u-row>
					</view>
				</u-card>
			</view>
		</view>
		<button type="default" @click="chongZhi()" class="but1">充值</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				dingdanID: '',
				title: "订单流水",
				Payname: '充值金额',
				load: false,
				load1: false,
				list: [],
				listXqing: [],
				reque: true,
				id: '',
				num: '',
				nonceStr: '',
				paySign: "",
				timeStamp: "",
				package: "",
				signType: "",
				pay_type: '',
				zhuangtai: '',
				arr: [{
					class: '#fa3534',
					text: '未完成',
					is_done: false,
					button:{
						
					}
				}, {
					class: '#18b566',
					text: '完成',
					is_done: true
				}, ],
			}
		},
		onBackPress() {
			console.log(2222)
			this.back();

		},
		onPullDownRefresh() {
			console.log('下拉刷新了')
			setTimeout(() => {
				this.zhifuListnav(() => {
					uni.stopPullDownRefresh()

				})
			}, 1000)
		},
		onLoad(options) {
			// console.log(options.projcet_id)
			// this.id=options.projcet_id
			// this.zhifuListnav(options.projcet_id)
			// this.listXqingnav(options.projcet_id)
			this.id = options.project_id
			console.log(this.id)
			this.zhifuListnav()
			this.listXqingnav()
		},
		mounted() {

		},
		methods: {
			back() {
				uni.navigateBack({
					delta: 2
				})
			},
			zhifuListnav() {
				let that = this
				this.$flyio.get('v1.Pay/payProjectRecharInfo', {
						project_id: that.id
					}).then((ret) => {
						console.log(ret)
						that.listXqing = ret.data.list.data;
						this.load = true;
						console.log(that.listXqing, 'that.listXqing')
						that.dingdanID = that.listXqing.id;
						console.log(that.dingdanID, "流水ID")
					})
					.catch((e) => {

					})
			},
			listXqingnav() {
				let that = this
				this.$flyio.get('v1.Pay/payProjectInfo', {
						project_id: that.id,
					}).then((ret) => {
						console.log(ret)
						this.list = ret.data;
						this.load1 = true;

					})
					.catch((e) => {

					})
			},
			chongZhi() {

				let that = this
				that.num = this.num
				that.list.project_surplus = this.list.project_surplus
				console.log(that.list.project_surplus, "222")
				console.log(that.num, "111")
				if (that.num == '' || isNaN(that.num * 1)) {
					that.request = false
					uni.showToast({
						title: "请输入正确金额"
					})
					return
				} else {
					this.$flyio.get('v1.Pay/PayOrder?project_id=' + this.id, {
							project_id: this.id,
							amount: this.num
						}).then((ret) => {
							console.log(ret)
							console.log(ret.data.timeStamp)
							wx.requestPayment({
								'timeStamp': ret.data.timeStamp,
								'nonceStr': ret.data.nonceStr,
								'package': ret.data.package,
								'signType': ret.data.signType,
								'paySign': ret.data.paySign,
								'success': function(res) {
									console.log(res, "11123")
									that.listXqingnav()
									that.zhifuListnav()
								},
								'fail': function(res) {},
								'complete': function(res) {}
							})
						})
						.catch((e) => {

						})
				}
			},

			//  else {
			// this.request = false
			// uni.showToast({
			// 	title: "请输入正确金额"
			// })
			// 	return


			// },
			onceZhifu(ids){
				this.$flyio.get('v1.Pay/ContinuePay', {
						project_rechar_id: ids
					}).then((ret) => {
						console.log(ret)
						this.chongZhi()
					})
					.catch((e) => {
				
					})
			},
			stopDingdan() {
				let that = this
				this.$flyio.get('v1.Pay/closePayProject', {
						project_id: that.id
					}).then((ret) => {
						console.log(ret)
						uni.redirectTo({
							url: './zhifu'
						})
					})
					.catch((e) => {

					})
			},
			stopLiushui(ids) {
				this.$flyio.get('v1.Pay/clostPayOrderRechar', {
						project_rechar_id: ids
					}).then((ret) => {
						console.log(ret)
						// uni.redirectTo({
						// 	url:'./zhifu'
						// })
						this.listXqingnav()
					})
					.catch((e) => {

					})
			},
		}
	}
</script>

<style scoped lang="scss">
	.content1 {
		padding-bottom: 120rpx;
	}

	.but1 {
		background: red;
		width: 750rpx;
		color: white;
		position: fixed;
		bottom: 1%;
		height: 100rpx;
		z-index: 1;
	}

	.wrap {
		padding: 24rpx;
	}

	.u-row {
		margin: 40rpx 0;
	}

	.demo-layout {
		height: 80rpx;
		border-radius: 8rpx;

	}

	.bg-purple {
		line-height: 80rpx;
	}

	.u-card-wrap {
		background-color: $u-bg-color;
		padding: 1px;
	}
</style>
